<?php
define('Copyright', 'QQ:11497576');
define('ROOT_PATH', $_SERVER["DOCUMENT_ROOT"].'/');
if (!defined('ROOT_PATH'))
exit('server time out');
if (!defined('Copyright') || Copyright != 'QQ:11497576')
exit('QQ:11497576');
include_once ROOT_PATH.'cnclass/class.php';

	if (configModel('opwww') == 1) exit(back($config['a6']));
		
if ($_SERVER["REQUEST_METHOD"] == 'POST')
{
	//驗證碼匹配
	//if ($_POST['code'] == $_SESSION['code'])
	if ($_POST['user'] !="")
	{

		//驗證用戶和密碼是否存在
		$loginName = checkStr($_POST['user'])?checkStr($_POST['user']):alert1("账号错误！！！");
		if (empty($_POST['pass'])){alert1("密码不能为空！！！");}	
		$loginPwd = md5($_POST['pass']);
		$db=new DB();
		$sql = "SELECT * FROM `cn_user` WHERE `kauser` = '{$loginName}' AND `kapassword` = '{$loginPwd}'   LIMIT 1 ";
		$result = $db->query($sql, 1);
		if ($result)
		{
	
			//判斷帳號是否已被停用
			if ($result[0]['stat'] == 1) exit(back("抱歉！您的帳號已被禁止使用，請和您的上線聯繫。"));
			$useronline = $db->query("SELECT id FROM cn_user WHERE g_out = 1  ", 3);
			if ($useronline > configModel('ggpz')) exit(back("系統繁忙!請稍後重試。"));
			$loginIp = GetIP();
			$loginDate = date("Y-m-d H:i:s");
			$tjid=md5($loginDate);
			$sql = "UPDATE `cn_user` SET `zlogin` = '{$loginDate}', `zip` = '{$loginIp}',`tjid` = '{$tjid}',`look` =look+1, `g_out` =1  WHERE `kauser` = '{$loginName}' AND `kapassword` = '{$loginPwd}'   ";		
			$db->query($sql, 2);	
			$qqWryInfo = ROOT_PATH.'cnclass/QQWry.Dat';
			$ip_s = ipLocation($loginIp, $qqWryInfo);
			$sql = "INSERT INTO tjj (username, ip, tjid, adddate,ipname,zt) VALUES ('{$loginName}','{$loginIp}','{$ip_s}',now(),'用户登录','5')";
			$db->query($sql, 2);
			$_SESSION['uid'] = $result[0]['id'];	
			$_SESSION['username'] = $result[0]['kauser'];	
			//dump($_SESSION['username']);
			$_SESSION['tjid']= $tjid;

			//dump($_SESSION['username']);
			include_once ROOT_PATH.'vip.php';
			exit;
		}
		else 
		{
			back("帳號或密碼錯誤!!!");
			exit;
		}
	} 
	else 
	{
		//back("验证码错误!");
		back("帳號或密碼錯誤!");
		exit;
	}
} 
else
{
	$num = array();
	for ($i=0; $i<4; $i++) 
	{
		$num[$i] = rand(0,9);
	}
	$num = join('', $num);
	$_SESSION['code'] = $num;
}


header("location: index.php");

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="format-detection" content="telephone=no">
    <title>登录</title>
    <link rel="stylesheet" href="./plugin/seedsui/seedsui.min.css">
	<style type="text/css">
		#loginbox{
			background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#cce6f6), color-stop(100%,#f9fcf4));
			min-height:370px;
		}
		
		.login_btm{
			position:absolute; 
			bottom:30px; 
			width:88%; 
			margin-left:6%;
		}
	</style>
</head>

<body ontouchstart="">
	<form id="loginbox" class="body-box" action="" method="post">

		<div class="group" style="margin-top:188px;">
			<div class="input-box" data-input="clear" style="border-width:0 0 1px 0;">
				<input name="user" type="text" placeholder="请输入账号"/>
		    	<i class="icon icon-clear-fill color-placeholder"></i>
			</div>
			<div class="input-box" data-input="reveal">
				<input name="pass" type="password" placeholder="请输入密码"/>
		    	<i class="icon icon-eye-fill color-placeholder"></i>
			</div>
		</div>
		
		<a class="button block" style="margin:20px 12px;" href="#"><button type="button" >登录</button></a>

	</form>
	
    <script src="./plugin/jquery/jquery.min.js"></script>
    <script src="./plugin/seedsui/seedsui.min.js"></script>

	<script>
	var f=new Form("#loginbox");

	</script>
</body>
</html>
